// 使用ABP框架的分布式事件系统
using System;
using Matrix.ServiceDiscovery.Enums;

namespace Matrix.ServiceDiscovery.Events
{
    /// <summary>
    /// 服务实例注册事件
    /// </summary>
    public class ServiceInstanceRegisteredEvent
    {
        /// <summary>
        /// 服务实例ID
        /// </summary>
        public Guid ServiceInstanceId { get; set; }

        /// <summary>
        /// 实例ID
        /// </summary>
        public string InstanceId { get; set; } = string.Empty;

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 注册时间
        /// </summary>
        public DateTime RegisterTime { get; set; }

        /// <summary>
        /// 服务地址
        /// </summary>
        public string? ServiceAddress { get; set; }

        /// <summary>
        /// 元数据
        /// </summary>
        public string? Metadata { get; set; }

        public ServiceInstanceRegisteredEvent()
        {
            RegisterTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 服务实例注销事件
    /// </summary>
    public class ServiceInstanceUnregisteredEvent
    {
        /// <summary>
        /// 服务实例ID
        /// </summary>
        public Guid ServiceInstanceId { get; set; }

        /// <summary>
        /// 实例ID
        /// </summary>
        public string InstanceId { get; set; } = string.Empty;

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 注销时间
        /// </summary>
        public DateTime UnregisterTime { get; set; }

        /// <summary>
        /// 注销原因
        /// </summary>
        public string? Reason { get; set; }

        public ServiceInstanceUnregisteredEvent()
        {
            UnregisterTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 服务实例健康状态变更事件
    /// </summary>
    public class ServiceHealthStatusChangedEvent
    {
        /// <summary>
        /// 服务实例ID
        /// </summary>
        public Guid ServiceInstanceId { get; set; }

        /// <summary>
        /// 实例ID
        /// </summary>
        public string InstanceId { get; set; } = string.Empty;

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 旧的健康状态
        /// </summary>
        public HealthStatus OldHealthStatus { get; set; }

        /// <summary>
        /// 新的健康状态
        /// </summary>
        public HealthStatus NewHealthStatus { get; set; }

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; }

        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public long ResponseTimeMs { get; set; }

        /// <summary>
        /// 错误信息（如果状态变为不健康）
        /// </summary>
        public string? ErrorMessage { get; set; }

        public ServiceHealthStatusChangedEvent()
        {
            ChangeTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 服务发现配置变更事件
    /// </summary>
    public class ServiceDiscoveryConfigChangedEvent
    {
        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 配置类型
        /// </summary>
        public string ConfigType { get; set; } = string.Empty;

        /// <summary>
        /// 旧配置
        /// </summary>
        public string? OldConfig { get; set; }

        /// <summary>
        /// 新配置
        /// </summary>
        public string? NewConfig { get; set; }

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; }

        /// <summary>
        /// 变更者
        /// </summary>
        public string? ChangedBy { get; set; }

        public ServiceDiscoveryConfigChangedEvent()
        {
            ChangeTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 服务实例元数据更新事件
    /// </summary>
    public class ServiceInstanceMetadataUpdatedEvent
    {
        /// <summary>
        /// 服务实例ID
        /// </summary>
        public Guid ServiceInstanceId { get; set; }

        /// <summary>
        /// 实例ID
        /// </summary>
        public string InstanceId { get; set; } = string.Empty;

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 更新的字段
        /// </summary>
        public List<string> UpdatedFields { get; set; } = new();

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }

        /// <summary>
        /// 更新者
        /// </summary>
        public string? UpdatedBy { get; set; }

        public ServiceInstanceMetadataUpdatedEvent()
        {
            UpdateTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 负载均衡策略变更事件
    /// </summary>
    public class LoadBalancingStrategyChangedEvent
    {
        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 旧策略
        /// </summary>
        public LoadBalancingStrategy OldStrategy { get; set; }

        /// <summary>
        /// 新策略
        /// </summary>
        public LoadBalancingStrategy NewStrategy { get; set; }

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; }

        /// <summary>
        /// 变更原因
        /// </summary>
        public string? Reason { get; set; }

        /// <summary>
        /// 变更者
        /// </summary>
        public string? ChangedBy { get; set; }

        public LoadBalancingStrategyChangedEvent()
        {
            ChangeTime = DateTime.Now;
        }
    }

    /// <summary>
    /// 服务实例TTL续期事件
    /// </summary>
    public class ServiceInstanceTtlRenewedEvent
    {
        /// <summary>
        /// 服务实例ID
        /// </summary>
        public Guid ServiceInstanceId { get; set; }

        /// <summary>
        /// 实例ID
        /// </summary>
        public string InstanceId { get; set; } = string.Empty;

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 续期时长（秒）
        /// </summary>
        public int RenewalSeconds { get; set; }

        /// <summary>
        /// 新的过期时间
        /// </summary>
        public DateTime NewExpirationTime { get; set; }

        /// <summary>
        /// 续期时间
        /// </summary>
        public DateTime RenewalTime { get; set; }

        public ServiceInstanceTtlRenewedEvent()
        {
            RenewalTime = DateTime.Now;
        }
    }
}